package com.fire.control.system.module.security.controller.web;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fire.control.system.dto.UserDTO;
import com.fire.control.system.module.common.controller.BaseController;
import com.fire.control.system.module.company.service.CompanyService;
import com.fire.control.system.module.security.service.ISecurityService;
import com.fire.control.system.standard.BusinessInterfaceStandard;
import com.fire.control.system.statics.Type_Role;
import com.fire.control.system.support.protocol.comman.ResponseProtocol;
import com.fire.control.system.support.protocol.security.SecurityRequestProtocol;

/**
 * @author liuxincheng
 * @ClassName: SecurityControl
 * @Description: TODO(安全控制器)
 * @date 2017年6月12日 上午10:14:51
 */
@RestController
@RequestMapping(path="web/securityCtr")
public class SecurityControl extends BaseController implements BusinessInterfaceStandard<SecurityRequestProtocol, ResponseProtocol> {
    
	@Autowired
	private ISecurityService securityService;
	
	@Autowired
	private CompanyService companyService;
	
	/**
	 * @author  liuxincheng
	 * @Title: getSecurityMangerList
	 * @Description: TODO(安全管理员列表查询)
	 * @param @param requestProtocol
	 * @param @param p
	 * @param @return    设定文件
	 * @return ResponseProtocol    返回类型
	 * @throws null
	 */
	@RequestMapping(path="getSecurityMangerList",method=RequestMethod.POST)
	public ResponseProtocol getSecurityMangerList(SecurityRequestProtocol requestProtocol){
		requestProtocol.setRoleType(Type_Role.security_manager);
		ResponseProtocol response =this.getSecurityListByCodition(requestProtocol);
		return response;
	}
	
	/**
	 * @author  liuxincheng
	 * @Title: getSafetyInspectionList
	 * @Description: TODO(安全巡检员列表查询)
	 * @param @param requestProtocol
	 * @param @param p
	 * @param @return    设定文件
	 * @return ResponseProtocol    返回类型
	 * @throws null
	 */
	@RequestMapping(path="getSafetyInspectionList",method=RequestMethod.POST)
	public ResponseProtocol getSafetyInspectionList(SecurityRequestProtocol requestProtocol){
		requestProtocol.setRoleType(Type_Role.security_patrol);
		ResponseProtocol response = this.getSecurityListByCodition(requestProtocol);
		return response;
	}
	
	
	private ResponseProtocol getSecurityListByCodition(SecurityRequestProtocol requestProtocol){
		requestProtocol.setTaskuuid(UUID.randomUUID().toString());
		UserDTO u = this.getUser();
		List<String> childrenCompanyIdList = companyService.getChildCompanyIdList(u.getCompany().getId());
		requestProtocol.setCompanyIds(childrenCompanyIdList);
		ResponseProtocol response = securityService.getSecurityListByCodition(requestProtocol);
		return response;
	}
	
	/**
	 * @author  liuxincheng
	 * @Title: saveSecurityOr
	 * @Description: TODO(添加安全管理员)
	 * @param @param requestProtocol
	 * @param @return    设定文件
	 * @return ResponseProtocol    返回类型
	 * @throws
	 */
	@RequestMapping(path="addSecurityOr",method=RequestMethod.POST)
	public ResponseProtocol saveSecurityOr(SecurityRequestProtocol requestProtocol){
		ResponseProtocol response = securityService.addSecurityOr(requestProtocol,this.getUser());
		return response;
	}
	
	/**
	 * @author  liuxincheng
	 * @Title: updateSecurityOr
	 * @Description: TODO(修改安全管理员)
	 * @param @param requestProtocol
	 * @param @param request
	 * @param @return    设定文件
	 * @return ResponseProtocol    返回类型
	 * @throws null
	 */
	@RequestMapping(path="updateSecurityOr",method=RequestMethod.POST)
	public ResponseProtocol updateSecurityOr(SecurityRequestProtocol requestProtocol){
		requestProtocol.setTaskuuid(UUID.randomUUID().toString());
		ResponseProtocol response = securityService.updateSecurityOrInfo(requestProtocol,this.getUser());
		return response;
	}
	
	/**
	 * @author  liuxincheng
	 * @Title: switchSecurityOrStatus
	 * @Description: TODO(转换巡检员状态)
	 * @param @param requestProtocol
	 * @param @return    设定文件
	 * @return ResponseProtocol    返回类型
	 * @throws null
	 */
	@RequestMapping(path="switchSecurityOrStatus",method=RequestMethod.POST)
	public ResponseProtocol switchSecurityOrStatus(SecurityRequestProtocol requestProtocol){
		requestProtocol.setTaskuuid(UUID.randomUUID().toString());
		ResponseProtocol response = securityService.switchSecurityOrStatus(requestProtocol,this.getUser());
		return response;
	}
	
	/**
	 * @author  liuxincheng
	 * @Title: deleteSecurityOr
	 * @Description: TODO(删除安全管理员)
	 * @param @param requestProtocol
	 * @param @param request
	 * @param @return    设定文件
	 * @return ResponseProtocol    返回类型
	 * @throws null
	 */
	@RequestMapping(path="deleteSecurityOr",method=RequestMethod.POST)
	public ResponseProtocol deleteSecurityOr(SecurityRequestProtocol requestProtocol){
		requestProtocol.setTaskuuid(UUID.randomUUID().toString());
		ResponseProtocol response = securityService.deleteSecurityOrInfo(requestProtocol);
		return response;
	}
	
	/**
	 * @author liuxincheng
	 * @Title: deleteSecurityOr
	 * @Description: TODO(获取安全人员密码)
	 * @param @param requestProtocol
	 * @param @return    设定文件
	 * @return ResponseProtocol    返回类型
	 * @throws null
	 */
	@RequestMapping(path="getSecurityOrPassWord",method=RequestMethod.POST)
	public ResponseProtocol getSecurityOrPassWord(SecurityRequestProtocol requestProtocol){
		requestProtocol.setTaskuuid(UUID.randomUUID().toString());
		ResponseProtocol response = securityService.getSecurityOrPassWord(requestProtocol);
		return response;
	}
	/******************************************其它业务接口***************************************************/
	/**
	 * @author liuxincheng
	 * @Title: getDeviceGroup
	 * @Description: TODO(获得设备组)
	 * @param @param requestProtocol
	 * @param @return    设定文件
	 * @return ResponseProtocol    返回类型
	 * @throws null
	 */
	@RequestMapping(path="getDeviceGroup",method=RequestMethod.POST)
	public ResponseProtocol getDeviceGroup(SecurityRequestProtocol requestProtocol){
		ResponseProtocol response = securityService.getDeviceGroup(requestProtocol,this.getUser());
		return response;
	}
	
	/**
	 * @author liuxincheng
	 * @Title: getSecuritOrDetail
	 * @Description: TODO(获得选中人员详情)
	 * @param @param requestProtocol
	 * @param @return    设定文件
	 * @return ResponseProtocol    返回类型
	 * @throws null
	 */
	@RequestMapping(path="getSecuritOrDetail",method=RequestMethod.POST)
	public ResponseProtocol getSecuritOrDetail(SecurityRequestProtocol requestProtocol){
		ResponseProtocol response = securityService.getSecuritOrDetail(requestProtocol);
		return response;
	}
	
	/**
	 * @author liuxincheng
	 * @Title: getParentSecuritOr
	 * @Description: TODO(获得该人员的上级管理员)
	 * @param @param requestProtocol
	 * @param @return    设定文件
	 * @return ResponseProtocol    返回类型
	 * @throws null
	 */
	@RequestMapping(path="getParentSecuritOr",method=RequestMethod.POST)
	public ResponseProtocol getParentSecuritOr(SecurityRequestProtocol requestProtocol){
		ResponseProtocol response = securityService.getParentSecuritOr(requestProtocol);
		return response;
	}
}
